﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Bitis_KeToanThue_Pro_DungChung.Common;
namespace Bitis_KeToanThue_Pro_DanhMuc.AccessDatabase
{
    class DanhMucVatTu
    {
        AccessData ac = new AccessData(1);
        public int them(string ten, string dvt, int nhom, string donvi)
        {
            SqlParameter[] arrpara= new SqlParameter[4];
            arrpara[0] = new SqlParameter("TenVT", SqlDbType.NVarChar);
            arrpara[1] = new SqlParameter("DVT", SqlDbType.NVarChar);
            arrpara[2] = new SqlParameter("MaNhomVT", SqlDbType.Int);
            arrpara[3] = new SqlParameter("MaDV", SqlDbType.Char);

            arrpara[0].Value = ten;
            arrpara[1].Value = dvt;
            arrpara[2].Value = nhom;
            arrpara[3].Value = donvi;

            DataTable dt = ac.ftblDocDuLieuSP("sp_themvattu", arrpara);
            return int.Parse(dt.Rows[0]["ErrCode"].ToString());
        }
        public int sua(int Mmavt,string ten, string dvt, int nhom, string donvi)
        {
            SqlParameter[] arrpara = new SqlParameter[5];
            arrpara[0] = new SqlParameter("MaVT", SqlDbType.Int);
            arrpara[1] = new SqlParameter("TenVT", SqlDbType.NVarChar);
            arrpara[2] = new SqlParameter("DVT", SqlDbType.NVarChar);
            arrpara[3] = new SqlParameter("MaNhomVT", SqlDbType.Int);
            arrpara[4] = new SqlParameter("MaDV", SqlDbType.Char);

            arrpara[0].Value = Mmavt;
            arrpara[1].Value = ten;
            arrpara[2].Value = dvt;
            arrpara[3].Value = nhom;
            arrpara[4].Value = donvi;

            DataTable dt = ac.ftblDocDuLieuSP("sp_suavattu", arrpara);
            return int.Parse(dt.Rows[0]["ErrCode"].ToString());
        }
        public int delete(int mavt)
        {
            SqlParameter[] arrpara = new SqlParameter[1];
            arrpara[0]=new SqlParameter("MaVT",SqlDbType.Int);
            arrpara[0].Value=mavt;
            DataTable dt=ac.ftblDocDuLieuSP("sp_xoaVT",arrpara);
            return int.Parse(dt.Rows[0]["ErrCode"].ToString());
        }
        public DataTable loadgrid()
        {
            return ac.ftblDocDuLieuSP("sp_loadVT", null);
        }
        public DataTable loadcombonhom()
        {
            return ac.ftblDocDuLieuSP("sp_loadcombonhom", null);
        }
        public DataTable loadcombodv()
        {
            return ac.ftblDocDuLieuSP("sp_loadcombodv", null);
        }
    }
}
